efi: Lock down the kernel if booted in secure boot mode
authorBen Hutchings <ben@decadent.org.uk>
Tue, 10 Sep 2019 10:54:28 +0000 (11:54 +0100)
committerSalvatore Bonaccorso <carnil@debian.org>
Thu, 13 Feb 2020 05:14:49 +0000 (05:14 +0000)
Based on an earlier patch by David Howells, who wrote the following
description:

> UEFI Secure Boot provides a mechanism for ensuring that the firmware will
> only load signed bootloaders and kernels.  Certain use cases may also
> require that all kernel modules also be signed.  Add a configuration option
> that to lock down the kernel - which includes requiring validly signed
> modules - if the kernel is secure-booted.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Topic features/all/lockdown
Gbp-Pq: Name efi-lock-down-the-kernel-if-booted-in-secure-boot-mo.patch

arch/x86/kernel/setup.c
drivers/firmware/efi/secureboot.c
include/linux/security.h
security/lockdown/Kconfig
security/lockdown/lockdown.c

index d10f42770190caf2b508c1621f64c6eff29a9ff1..d9dd91c9d9de543591d2890ccae6ee4a593aea8a 100644 (file)
@@ -1027,6 +1027,8 @@ void __init setup_arch(char **cmdline_p)
        if (efi_enabled(EFI_BOOT))
                efi_init();
 
+       efi_set_secure_boot(boot_params.secure_boot);
+
        dmi_setup();
 
        /*
@@ -1179,8 +1181,6 @@ void __init setup_arch(char **cmdline_p)
        /* Allocate bigger log buffer */
        setup_log_buf(1);
 
-       efi_set_secure_boot(boot_params.secure_boot);
-
        reserve_initrd();
 
        acpi_table_upgrade();
index bf16cfb6a028849a87a711e41c1eb74c1e53d8e6..b56f262ecd07950b645b8b28df6223bb27c96e87 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/efi.h>
 #include <linux/kernel.h>
 #include <linux/printk.h>
+#include <linux/security.h>
 
 /*
  * Decide what to do when UEFI secure boot mode is enabled.
@@ -28,6 +29,8 @@ void __init efi_set_secure_boot(enum efi_secureboot_mode mode)
                        break;
                case efi_secureboot_mode_enabled:
                        set_bit(EFI_SECURE_BOOT, &efi.flags);
+                       lock_kernel_down("EFI Secure Boot",
+                                        LOCKDOWN_CONFIDENTIALITY_MAX);
                        pr_info("Secure boot enabled\n");
                        break;
                default:
index 9df7547afc0cb783883b5c5c7b32b2956a650d7a..3d8713301e7bb9465952eeb694416f82244bd9d3 100644 (file)
@@ -443,6 +443,7 @@ int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);
 int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen);
 int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen);
 int security_locked_down(enum lockdown_reason what);
+int lock_kernel_down(const char *where, enum lockdown_reason level);
 #else /* CONFIG_SECURITY */
 
 static inline int call_blocking_lsm_notifier(enum lsm_event event, void *data)
@@ -1270,6 +1271,11 @@ static inline int security_locked_down(enum lockdown_reason what)
 {
        return 0;
 }
+static inline int
+lock_kernel_down(const char *where, enum lockdown_reason level)
+{
+       return -EOPNOTSUPP;
+}
 #endif /* CONFIG_SECURITY */
 
 #ifdef CONFIG_SECURITY_NETWORK
index e84ddf48401010bcc0829a32db58e6f12bfdedcb..628a87dd1b6b5a55b7273281147a6f85d81d42e7 100644 (file)
@@ -45,3 +45,18 @@ config LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY
         disabled.
 
 endchoice
+
+config LOCK_DOWN_IN_EFI_SECURE_BOOT
+       bool "Lock down the kernel in EFI Secure Boot mode"
+       default n
+       depends on SECURITY_LOCKDOWN_LSM
+       depends on EFI
+       select SECURITY_LOCKDOWN_LSM_EARLY
+       help
+         UEFI Secure Boot provides a mechanism for ensuring that the firmware
+         will only load signed bootloaders and kernels.  Secure boot mode may
+         be determined from EFI variables provided by the system firmware if
+         not indicated by the boot parameters.
+
+         Enabling this option results in kernel lockdown being
+         triggered in confidentiality mode if EFI Secure Boot is set.
index 40b790536defaf8dcdad0655d4423f33c94dcd06..01b60402320fdd7c55fcb109852a4a15812d1836 100644 (file)
@@ -48,7 +48,7 @@ static const enum lockdown_reason lockdown_levels[] = {LOCKDOWN_NONE,
 /*
  * Put the kernel into lock-down mode.
  */
-static int lock_kernel_down(const char *where, enum lockdown_reason level)
+int lock_kernel_down(const char *where, enum lockdown_reason level)
 {
        if (kernel_locked_down >= level)
                return -EPERM;